(function(){

    var elements = [];
    function Food(width, height, color){
        this.width = width || 20;
        this.height = height || 20;
        this.color = color || 'yellow';
        this.x = 0;
        this.y = 0;
    }
    Food.prototype.init = function(map){
        remove();
        var div = document.createElement('div');
        map.appendChild(div);
        elements.push(div)
        div.style.position = 'absolute';
        div.style.zIndex = '10000';
        div.style.width = this.width + 'px';
        div.style.height = this.height + 'px';
        div.style.background = this.color;
        this.x  =  Math.round(Math.random()*map.offsetWidth/this.width);
        this.y =  Math.round(Math.random()*map.offsetHeight/this.height);

        div.style.left = this.x * this.width + 'px';
        div.style.top = this.y * this.height + 'px';
    };
    function remove(){
        for(var i=0; i<elements.length; i++){
            elements[i].parentNode.removeChild(elements[i]);
            elements.splice(i,1);
        }
    }

    window.Food = Food;
}());

